﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DBService;

public partial class administration_Default2 : System.Web.UI.Page
{
    ModelAdapter adapter = null;

    protected void Page_Load(object sender, EventArgs e)
    {
        adapter = new ModelAdapter();
    }

    protected void SFindID_Click(object sender, EventArgs e)
    {
        //adapter = new ModelAdapter();
        gridBind(getcompanyID());
    }
    
    public int? getcompanyID()
    {
        int companyID;
        if (int.TryParse(textid.Value, out companyID))
        {
            return companyID;
        }
        else
        {
            return null;
        }
    }

    public void gridBind(int? comID)
    {
        ReviewGridView.DataSource = adapter.getReviewByCompanyIDOrAll(comID);
        ReviewGridView.DataBind();
    }

    protected void ReviewGridView_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName.Equals("RestoreCommand"))
        {
            int row = Int32.Parse(e.CommandArgument.ToString());
            var revID = int.Parse(ReviewGridView.Rows[row].Cells[1].Text.ToString());
            adapter.RestoreRreviwByID(revID);
            gridBind(getcompanyID());
        }
    }
}